#ifndef CLIENT_H
#define CLIENT_H

#include <stdint.h>
#include <QWidget>
#include <QTcpSocket>
#include <QListWidgetItem>
#include <QFileDialog>
#include <QDesktopServices>
#include <QMessageBox>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "constant.h"
#include "Headers/algorithm.h"
#include "filethread.h"

namespace Ui { class client; }

class client : public QWidget
{
    Q_OBJECT

public:
    client(QWidget *parent = nullptr);
    ~client();

private:
    Ui::client *ui;
private:
    /*Messages Show*/
    void dealMessage(QNChatMessage *messageW, QListWidgetItem *item, QString text, QString newtext,QString time, QNChatMessage::User_Type type);
    void dealMessageTime(QString curMsgTime);
    void dealimage(QNChatMessage *messageW, QListWidgetItem *item, QString filePath, QString time,  QNChatMessage::User_Type type);
protected:
    void resizeEvent(QResizeEvent *event);
    void closeEvent(QCloseEvent *event);
private slots:
    void on_pushButton_released();
    void on_pushButton_2_clicked();
    void on_pushButton_6_released();

    void on_pushButton_3_released();

    void on_pushButton_7_released();

    void on_pushButton_4_released();

private:
    QString m_downloadPath;
    Emijo *MyEmijo;
    ChatBOT *chatbot;
    QString apiKey;
    QString groupId;
    FileThread *fileThread;
    /*Port*/
    qint64 MessagesTcpPort;
    qint64 setVidoTcpPort;
    qint64 getVidoTcpPort;
    /*Socket*/
    QTcpSocket* MessagesTcpSocket;
    QTcpSocket *setVidoTcpSocket;
    QTcpSocket *getVidoTcpSocket;
    /*Socket Init*/
    void MessagesSockerInit();
    void ChatBotInit();
    void setVidoInit();
    void getVidoInit();
    /*File*/
    QString ServerFilePath;
    QString toServerFileSize;
    bool is_images;
    QMap<QString,QVector<QPair<QNChatMessage*,QString>>>toServerFileViewList;
    QMap<QString,QVector<QPair<QNChatMessage*,QString>>>getServerFileViewList;
    QString User;
    /*Vido*/
    void openVido();
    void closeVido();
    void VidoData();
    Vido* vido;
    int is_videoShow;
    cv::VideoCapture *capture;
    QPixmap pixmap;
public:
    QString ServerIp;
    QString UserName;
    QString ToUserName;
signals:
    void sendMessage(QString);
};
#endif // CLIENT_H
